package com.renzhebiao.lkang.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.plugins.Page;
import com.renzhebiao.lkang.base.BaseService;
import com.renzhebiao.lkang.entity.UserPO;
import com.renzhebiao.lkang.mapper.UserMapper;
import com.renzhebiao.lkang.page.PageDTO;
import com.renzhebiao.lkang.page.PaginationDTO;
import com.renzhebiao.lkang.query.UserQuery;
import com.renzhebiao.lkang.request.RequestCache;
import com.renzhebiao.lkang.service.IUserService;
import com.renzhebiao.lkang.utils.BeanCopys;
import com.renzhebiao.lkang.utils.PasswordEncoder;

@Service
public class UserService extends BaseService<UserPO> implements IUserService {

    @Autowired
    UserMapper      userMapper;
    @Autowired
    PasswordEncoder passwordEncoder;

    @Override
    public void add(UserPO po) {
        po.allEx(RequestCache.userId());

        this.userMapper.insert(po);
    }

    @Override
    public void edit(UserPO po) {
        po.updated(RequestCache.userId());
        this.userMapper.updateById(po);
    }

    @Override
    public void delete(Long id) {
        this.deleteByLogic(id, UserPO.class);
    }

    @Override
    public List<UserPO> getUserList(UserQuery po) {

        return this.userMapper.selectByMap(BeanCopys.toMap(po));
    }

    @Override
    public UserPO getUser(Long id) {

        return this.userMapper.selectById(id);
    }

    @Override
    public PageDTO<UserPO> getUserByPage(PaginationDTO<UserQuery, Void> paging) {

        Page<UserPO> page = this.getPage(paging);
        List<UserPO> pos = this.userMapper.getUserByPage(page, page.getCondition());
        return this.getPage(page, pos);
    }
}
